/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.alxbrendmaquinarias.model;

import java.io.Serializable;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Max
 */
@Entity
@Table(name = "product", catalog = "sgcom", schema = "")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Product.findAll", query = "SELECT p FROM Product p"),
    @NamedQuery(name = "Product.findNameCode", query = "SELECT p FROM Product p WHERE p.productId LIKE :code AND p.name LIKE :name"),
    @NamedQuery(name = "Product.findCode", query = "SELECT p FROM Product p WHERE p.productId LIKE :code"),
    @NamedQuery(name = "Product.findName", query = "SELECT p FROM Product p WHERE p.name LIKE :name"),
    @NamedQuery(name = "Product.findById", query = "SELECT p FROM Product p WHERE p.id = :id"),
    @NamedQuery(name = "Product.findByMinStock", query = "SELECT p FROM Product p WHERE p.minStock = :minStock"),
    @NamedQuery(name = "Product.findByMaxStock", query = "SELECT p FROM Product p WHERE p.maxStock = :maxStock"),
    @NamedQuery(name = "Product.count", query = "SELECT count(p.id) FROM Product p")})

public class Product implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id")
    private Integer id;
    @Size(max = 11)
    @Column(name = "product_id")
    private String productId;
    @Size(max = 100)
    @Column(name = "name")
    private String name;
    @Column(name = "min_stock")
    private Integer minStock = 1;
    @Column(name = "max_stock")
    private Integer maxStock = 2;
    @OneToMany(mappedBy = "productId")
    private List<DetailSaleProduct> detailSaleProductList;
    @OneToMany(mappedBy = "productId")
    private List<ProductShop> productShopList;
    @OneToMany(mappedBy = "productId")
    private List<StorehouseProduct> storehouseProductList;
    @JoinColumn(name = "unit_type_id", referencedColumnName = "id")
    @ManyToOne
    private UnitType unitTypeId;
    @JoinColumn(name = "category_id", referencedColumnName = "id")
    @ManyToOne
    private Category categoryId;
    @JoinColumn(name = "mark_id", referencedColumnName = "id")
    @ManyToOne
    private Mark markId;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "productId")
    private List<DetailInputDocument> detailInputDocumentList;
    @Transient
    private String fullName;

    public Product() {
    }

    public Product(Integer id) {
        this.id = id;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getMinStock() {
        return minStock;
    }

    public void setMinStock(Integer minStock) {
        this.minStock = minStock;
    }

    public Integer getMaxStock() {
        return maxStock;
    }

    public void setMaxStock(Integer maxStock) {
        this.maxStock = maxStock;
    }

    @XmlTransient
    public List<DetailSaleProduct> getDetailSaleProductList() {
        return detailSaleProductList;
    }

    public void setDetailSaleProductList(List<DetailSaleProduct> detailSaleProductList) {
        this.detailSaleProductList = detailSaleProductList;
    }

    @XmlTransient
    public List<ProductShop> getProductShopList() {
        return productShopList;
    }

    public void setProductShopList(List<ProductShop> productShopList) {
        this.productShopList = productShopList;
    }

    @XmlTransient
    public List<StorehouseProduct> getStorehouseProductList() {
        return storehouseProductList;
    }

    public void setStorehouseProductList(List<StorehouseProduct> storehouseProductList) {
        this.storehouseProductList = storehouseProductList;
    }

    public UnitType getUnitTypeId() {
        return unitTypeId;
    }

    public void setUnitTypeId(UnitType unitTypeId) {
        this.unitTypeId = unitTypeId;
    }

    public Category getCategoryId() {
        return categoryId;
    }

    public void setCategoryId(Category categoryId) {
        this.categoryId = categoryId;
    }

    public Mark getMarkId() {
        return markId;
    }

    public void setMarkId(Mark markId) {
        this.markId = markId;
    }

    @XmlTransient
    public List<DetailInputDocument> getDetailInputDocumentList() {
        return detailInputDocumentList;
    }

    public void setDetailInputDocumentList(List<DetailInputDocument> detailInputDocumentList) {
        this.detailInputDocumentList = detailInputDocumentList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Product)) {
            return false;
        }
        Product other = (Product) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        if ((this.productId == null && other.productId == null) || (this.productId != null && !this.productId.equals(other.productId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.alxbrendmaquinarias.model.Product[ id=" + id + " ]";
    }

    public String getProductId() {
        return productId;
    }

    public void setProductId(String productId) {
        this.productId = productId;
    }

    public String getFullName() {
        try {
         StringBuilder sb = new StringBuilder();
        sb.append(categoryId.getName()).append(" ");
        sb.append(markId.getName()).append(" ");
        sb.append(name);
        fullName = sb.toString();   
        } catch (Exception e) {
            
        }
        return fullName;
    }

    public void setFullName(String fullName) {
        this.fullName = fullName;
    }
}
